package com.bank.common.exception;


import cn.hutool.core.util.StrUtil;

public class ParamException extends GlobalException {
	private static final long serialVersionUID = 6021390821349937519L;

	private static final String msg = "请求参数异常";

	public ParamException(String message) {
		super(400,message);
	}

	public static void isTrue(boolean expression, String message) {
		if (expression) {
			throwException(message);
		}
	}

	public static void isTrue(boolean expression) {
		if (expression) {
			throwException(msg);
		}
	}

	public static void isFalse(boolean expression, String message) {
		if (!expression) {
			throwException(message);
		}
	}
	public static void isFalse(boolean expression) {
		if (!expression) {
			throwException(msg);
		}
	}

	public static void isNull(Object object, String message) {
		if (object == null) {
			throwException(message);
		}
	}

	public static void isNull(Object object, String message,Object... params) {
		if (object == null) {
			throwException(StrUtil.format(message,params));
		}
	}

	public static void isNotNull(Object object, String message) {
		if (object != null) {
			throwException(message);
		}
	}


	public static void isNull(Object obj) {
		isNull(obj, msg);
	}

	public static void isBlank(String text, String message) {
		if (StrUtil.isBlank(text)) {
			throwException(message);
		}
	}

	public static void isBlank(String text) {
		isBlank(text, msg);
	}

	private static void throwException(String msg){
		throw new ParamException(msg);
	}
}
